package com.tms.app.tms.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ldoublem.loadingviewlib.view.LVCircularRing;
import com.tms.app.tms.R;
import com.tms.app.tms.app.Constant;

/**
 * Created by hl on 2017/6/22.
 */

public class MyDialogPhoto {
    LVCircularRing mLoadingView;
    Dialog mLoadingDialog;

    public MyDialogPhoto(Context context, View.OnClickListener listener) {

    }
    public MyDialogPhoto(Context context, View.OnClickListener listener, int hideTop3) {

        // 首先得到整个View
        View view = LayoutInflater.from(context).inflate( R.layout.layout_dialog_photo, null);
        // 获取整个布局
        LinearLayout layout = (LinearLayout) view.findViewById(R.id.dialog_view);
        TextView textView1=view.findViewById(R.id.dialog_photo_text_top_1);
        TextView textView2=view.findViewById(R.id.dialog_photo_text_top_2);
        TextView textView3=view.findViewById(R.id.dialog_photo_text_top_3);
        TextView button1=view.findViewById(R.id.dialog_photo_button_1);
        TextView button2=view.findViewById(R.id.dialog_photo_button_2);
        textView1.setOnClickListener(listener);
        textView2.setOnClickListener(listener);
        textView3.setOnClickListener(listener);
        button1.setOnClickListener(listener);
        button2.setOnClickListener(listener);
        switch (hideTop3){
            case 0:
                break;
            case 1:
                textView3.setVisibility(View.GONE);
        }


        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mLoadingDialog!=null&&mLoadingDialog.isShowing())
                {
                    mLoadingDialog.dismiss();
                    mLoadingDialog=null;
                }
            }
        });


        // 创建自定义样式的Dialog
     //   mLoadingDialog = new Dialog(context, R.style.loading_dialog);
        mLoadingDialog = new Dialog(context);
        // 设置返回键无效
        mLoadingDialog.setCancelable(true);
        mLoadingDialog.setCanceledOnTouchOutside(true);
//        mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(
//                LinearLayout.LayoutParams.MATCH_PARENT,
//                LinearLayout.LayoutParams.MATCH_PARENT));
        mLoadingDialog.setContentView(view);
    }



    public void show(){
        mLoadingDialog.show();
    }

    public boolean isShowing(){
        if (mLoadingDialog==null)
            return false;
        return mLoadingDialog.isShowing();
    }

    public void close(){
        if (mLoadingDialog!=null) {
            if (isShowing())
                mLoadingDialog.dismiss();
            mLoadingDialog=null;
        }
    }
}
